package app.myproject;

import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class CheckUserServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        UserService userService = UserServiceFactory.getUserService();

        String thisURL = req.getRequestURI();

        resp.setContentType("text/html");
        if (req.getUserPrincipal() != null) {
            resp.getWriter().println("" + req.getUserPrincipal().getName() +
                                     "<a href=\"" + userService.createLogoutURL(thisURL) + "\">[sign out]</a>");
            resp.getWriter().println("<br/>");
            resp.getWriter().println("User Info:<br/>");
            resp.getWriter().println("User Id = " + userService.getCurrentUser().getUserId() + "<br/>");
            resp.getWriter().println("Nickname = " + userService.getCurrentUser().getNickname() + "<br/>");
            resp.getWriter().println("Email = " + userService.getCurrentUser().getEmail() + "<br/>");            
            resp.getWriter().println("Auth Domain = " + userService.getCurrentUser().getAuthDomain() + "<br/>");
            resp.getWriter().println("Federated Identity = " + userService.getCurrentUser().getFederatedIdentity() + "<br/>");


        } else {
            resp.getWriter().println("<a href=\"" + userService.createLoginURL(thisURL) + "\">[sign in]</a>");
        }
    }

}
